﻿using RPAVIEW.util;
using RPAVIEW.views.controlLibrary;
using RPAVIEW.views.OtherPages;
using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.util;
using System.Windows;
using System.Windows.Controls;

namespace RPAVIEW.views.EditPage.flows.DealDownLoadDialogN {
    /// <summary>
    /// Input.xaml 的交互逻辑
    /// </summary>
    public partial class Input:BaseParamViewAction{
        public Input() {
            InitializeComponent();
            DealDownLoadDialogNParam param = ParamUtil.GetCurrentParam<DealDownLoadDialogNParam>();
            if(param.RenameDownloadFile) {
                RameFileChecked(null, null);
            } else { 
                RenameFileUnchecked(null, null);
            }

            if(param.WaitingDownloadFinish) {
                WaitDownloadChecked(null, null);
            } else { 
                WaitDownloadUnchecked(null, null);
            }
        }

        public override void UpdateSource() {
            this.savePath.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.renameDownloadFile.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
            this.saveFileName.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.waitingDownloadFinish.GetBindingExpression(CheckBox.IsCheckedProperty).UpdateSource();
            this.expireTime.GetBindingExpression(SelVarTextBox.text).UpdateSource();
            this.browserType.GetBindingExpression(ComboBox.SelectedIndexProperty).UpdateSource();
            this.buttonType.GetBindingExpression(ComboBox.SelectedIndexProperty).UpdateSource();
        }

        private void SelectSavePath(object sender, RoutedEventArgs e) {
            System.Windows.Forms.FolderBrowserDialog saveDialog =  FileUtil.OpenFloderSelectDialog();
            System.Windows.Forms.DialogResult dialogResult = saveDialog.ShowDialog();
            //按下确定选择的按钮  
            if(dialogResult == System.Windows.Forms.DialogResult.OK) {
                //记录选中的目录
                this.savePath.Text = saveDialog.SelectedPath;
            }
        }

        private void RameFileChecked(object sender, RoutedEventArgs e) {
            this.fileNameRow.Height = GridLength.Auto;
        }

        private void RenameFileUnchecked(object sender, RoutedEventArgs e) {
             this.fileNameRow.Height = new GridLength(0);
        }

        private void WaitDownloadUnchecked(object sender, RoutedEventArgs e) {
            this.expireTimeRow.Height = new GridLength(0);
        }

        private void WaitDownloadChecked(object sender, RoutedEventArgs e) {
            this.expireTimeRow.Height = GridLength.Auto;
        }

        private void ChangeButtonType(object sender, SelectionChangedEventArgs e) {
            FlowEditWindow editWin = WindowUtil.GetWindow<FlowEditWindow>();
            //按钮变为取消需要吧输出等信息都隐藏
            if(this.buttonType.SelectedIndex == 0) {
                this.renameCheckRow.Height = GridLength.Auto;
                this.expireCheckRow.Height = GridLength.Auto;
                if(this.renameDownloadFile.IsChecked ?? false) { 
                    this.fileNameRow.Height = GridLength.Auto;
                } else { 
                    this.fileNameRow.Height = new GridLength(0);
                }
                if(this.waitingDownloadFinish.IsChecked ?? false) { 
                    this.expireTimeRow.Height = GridLength.Auto;
                } else { 
                    this.expireCheckRow.Height = GridLength.Auto;            
                }
                this.parentPathRow.Height = GridLength.Auto;
                editWin.General.output.Visibility = Visibility.Visible;
            } else { 
                //取消
                this.parentPathRow.Height = new GridLength(0);
                this.renameCheckRow.Height = new GridLength(0);
                this.expireCheckRow.Height = new GridLength(0);
                this.fileNameRow.Height = new GridLength(0);
                this.expireTimeRow.Height = new GridLength(0); 
                editWin.General.output.Visibility = Visibility.Collapsed;
            }
        }
    }
}
